<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\user;

use App\Kernel\Util\UserJwtInstance;
use App\Middleware\User\UserMiddleware;

use App\Service\User\IntegralDetailService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 用户积分控制器
 *
 * @AutoController()
 * @Middleware(UserMiddleware::class)
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\admin
 */
class WalletController extends Controller
{
    /**
     * @Inject
     * @var IntegralDetailService
     */
    private $integral_detail_service;

    /**
     * 用户积分接口
     *
     */
    public function integral()
    {
        $user = UserJwtInstance::instance()->build()->getUser();

        $start_time = (string)$this->request->input('start_time', '');
        $type = (int)$this->request->input('type', '');

        $list = $this->integral_detail_service->integral($start_time, $type);

        $result = [
            'consume_integral' => $this->integral_detail_service->getIntegralBalanceByConsume($user->id),
            'share_integral' => $this->integral_detail_service->getIntegralBalanceByShare($user->id),
            'total_integral' => $this->integral_detail_service->getIntegralBalance($user->id),
            'list' => $list
        ];

        $this->success($result);
    }

}